package com.fingard.dsp.bank.reqrespobj.authcancelforrec;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.authforrec.detail.RetAtsQryAuthForRecDetail;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextWriter;

public class RetAtsQryAuthCancelForRec extends RetAtsBase {
    public RetAtsQryAuthCancelForRec(ReqRespHeader p_header) {
        retHeader = p_header;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
        reqSeqID = retHeader.reqSeqID;
    }

    public String respCode;
    public String respInfo;
    public String reqSeqID;
    public String resultType;
    public String transState;
    public String payInfoCode;
    public String reconcilyNo;

    private int writeRdCount = 0;

    public int getWriteRdCount() {
        return writeRdCount;
    }

    private boolean hasWriteHead = false;

    public void writeRetHead() {
        retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        retXmlWriter.writeElementString("RespCode", respCode);
        retXmlWriter.writeElementString("RespInfo", respInfo);
        retXmlWriter.writeElementString("ResultType", resultType);
        retXmlWriter.writeElementString("TransState", transState);
        retXmlWriter.writeElementString("PayInfoCode", payInfoCode);
        retXmlWriter.writeElementString("ReconcilyNo", reconcilyNo);
        hasWriteHead = true;
    }

    public void writeRetDetail(RetAtsQryAuthForRecDetail p_detail) {
        writeRdCount++;
        if (writeRdCount == 1 && !hasWriteHead) {
            if (StringHelper.isNullOrEmpty(respCode)) {
                respCode = "0";
                respInfo = "success";
            }
            writeRetHead();
        }
        retXmlWriter.writeStartElement("DetailRecord");
        retXmlWriter.writeElementString("PayCode", p_detail.payCode);
        retXmlWriter.writeElementString("ISeqno", p_detail.iSeqno);
        retXmlWriter.writeElementString("PayInfo", p_detail.payInfo);
        retXmlWriter.writeElementString("ContractNo", p_detail.contractNo);
        retXmlWriter.writeElementString("PayType", p_detail.payType);
        retXmlWriter.writeElementString("PayNo", p_detail.authCode);
        retXmlWriter.writeElementString("PayAcctName", p_detail.oppActName);
        retXmlWriter.writeElementString("PayAcctNo", p_detail.oppAct);
        retXmlWriter.writeElementString("DeadLine", p_detail.deadLine);
        retXmlWriter.writeElementString("TransState", p_detail.transState);
        retXmlWriter.writeEndElement();
    }

    public void writeAfterDetail() {
        if (!hasWriteHead) {
            writeRetHead();
        }
        writeEnd();//写结束
    }
}
